<%@ page contentType="application/json;charset=UTF-8" language="java" %><%--
--%><%@ page import="java.util.Collection" %><%--
--%><%@ page import="o.json.JSONFactory" %><%--
--%><%@ page import="o.json.JSONValue" %><%--
--%><%@ page import="o.json.JSONWriter" %><%--
--%><%@ page import="com.google.appengine.api.users.User" %><%--
--%><%@ page import="com.google.appengine.api.users.UserService" %><%--
--%><%@ page import="com.google.appengine.api.users.UserServiceFactory" %><%--
--%><%@ page import="wwiii.Game" %><%--
--%><%@ page import="wwiii.GameManager" %><%--
--%><%

	final UserService us = UserServiceFactory.getUserService();
	if (!us.isUserLoggedIn()) {
		response.sendError(HttpServletResponse.SC_UNAUTHORIZED);
		return;
	}
	final User user = us.getCurrentUser();

	final GameManager gm = new GameManager();
	gm.clearGames();

	final Collection<Game> games = gm.loadGames();

	final JSONWriter writer = new JSONWriter();
	final JSONFactory factory = new JSONFactory();
	writer.write(factory.create(games));

%><%= writer.toString() %>
